home *** CD-ROM | disk | FTP | other *** search
- The following is a Pascal assignment that I had in data structures. It
- implements a doubly linked queue, a doubly linked circular queue, and a binary
- search tree for storing data using pointers. It is probably of use to you if
- you want to learn something about the previously stated data structures and
- pointers. Before digging into the code perhaps you want to get a book on
- data structures and read up on the above data structures. Happy computing!!
-
- Chris Maeder
-
-
- QUEUE AND TREE ASSIGNMENT
-
- Data Structures
- Fall 1985
-
- Overview:
-
- In this assignment you will process mail orders for a sporting goods store.
- You will use queues to hold the transactions waiting to be processed and a
- binary search tree to hold the merchandise the store carries. For the
- queues and tree you must use the Pascal pointer type (linked list
- implementation).
-
- Transactions are processed one day at a time. At the end of every day,
- print summary information. At the very end of the program, print the
- binary search tree.
-
- Codes:
-
- The transaction codes are N, A, R, and S. Additional codes are * and X.
-
- N Insert a brand new item into the store's inventory.
- A Add a quantity to an existing item.
- R Remove an item from the store's inventory.
- S Sell a quantity of an existing item.
- * Add or delete a clerk.
- X Marks the end of a day.
-
- Exact syntax is as follows:
-
- N item_name quantity
- A item_name quantity
- R item_name
- S item_name quantity
- * HIRE clerk_name
- * QUIT clerk_name
- X day 1
-
- Note that you do not have to do any error checking for proper syntax, non-
- existant codes, or whatever. All input is correct.
-
- Item_names are a maximum of 20 characters. Quantities are integers.
- Clerk_names are a maximum of 25 characters. The phrase after an X is just
- there for readability of the data file.
-
- Details on transaction processing:
-
- Each day N, A, R, and S codes may come in. They will come in any order.
- You will want to process the N and A transactions first so there are more
- items and quantities for the sales. S transactions should be done next
- first come, first serve. If a sale order cannot be filled, leave it on
- the queue as the first sale order to be processed the following day.
- R codes are processed last each day. After an item is removed, if someone
- tries to buy that item, it will not be there (you will have removed it
- from the tree).
-
- As long as you use queues to hold transactions, you can use whatever
- variety you like (e.g. doubly linked, one queue, 2, 3, 4, priority queue).
- For each transaction processed, print an appropriate message.
-
- Details on clerks:
-
- The clerks get bored doing mail order transactions so a rotating schedule
- is set up. Each clerk does just two transactions (N, A, R, or S codes).
- Then the next clerk does two and so on. If a new clerk is added to the
- schedule with a HIRE command, he/she is added to the circular queue in the
- spot behind the current head node (i.e. added to the end of the current
- cycle to have time to learn the system). Occasionally, clerks get fed up
- with the job ad quit (QUIT). They would be removed from the schedule at
- the time of the QUIT command is read. To facilitate deletions, use double
- links for the circular list.
-
- At the end of every day, after the transactions for the day are printed,
- print the list of current clerks.
-
- Also, print the name of the clerk who handled each transaction when you
- print that transaction.
-
- The store inventory:
-
- Rather than using heaps, sorted arrays, or hashing to keep the store
- inventory, use a binary search tree. You will need algorithms for
- inserting into the tree, deleting from the tree, and searching the tree.
- Also, at the very end of the program you will print all the items in the
- tree in alphabetical order using a recursive inorder traversal.
-
- Output:
-
- Output must be very clear and well spaced. Output should be organized by
- days.
-
- Print each transaction as it is processed. As long as all input data is
- output in a readable fashion, you do not have to exactly echo print it.
- Also remember to print the clerk handling the transaction. At the end of
- every day, print a list of current clerks and print a list of items left
- on the queue.
-
- At the very end, skip an appropriate number of lines and use a title before
- printing the tree. For 3 points extra credit, the tree may be printed in
- tree form in addition to printing its contents in alphabetical order.